﻿@{
    ViewBag.Title = "原材料入库";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<link href="~/Content/css/yclk_stock_print.css" rel="stylesheet" media="print" />
<style type="text/css">
    .print {
        display: none;
    }
</style>
<script>
    var printItemTemplate = "";
    var currRowId = 0;
    var isJump = false;
    var currStatus = '@ViewBag.status';
    var AccountDate = '@ViewBag.accountDate';
    var columns = [
        {
            label: '<a id="grid_chb_selectAll" onclick="grid_chb_selectAll()">全选</a>', name: '', width: 40, align: 'center', sortable: false, frozen: true, formatter: function (cellvalue, options, rowObject) {
                return '<input class="grid_chb_select" value="' + rowObject.FDocuNO + '" name="checkbox" type="checkbox" onclick="" style="vertical-align:middle">';
            }
        },
        { label: '发生方式', name: 'FDocuTypeName', width: 80, align: 'center', sortable: false, frozen: true },
        { label: '单据编号', name: 'FDocuNO', width: 130, align: 'center', sortable: false, frozen: true },
        { label: '单据日期', name: 'FCurDate', width: 80, align: 'center', sortable: false, frozen: true },
        { label: '来料单位', name: 'FHappenComNO', width: 80, align: 'center', sortable: false },
        { label: '来料单位名称', name: 'FHappenComName', width: 130, align: 'left', sortable: false },
        { label: '合同编号', name: 'FCertificateListID', width: 130, align: 'left', sortable: false },
        { label: '材料分类', name: 'MaterialName', width: 80, align: 'left', sortable: false },
        { label: '材料牌号', name: 'MaterialCode', width: 80, align: 'left', sortable: false },
        { label: '材料规格', name: 'MaterialSizes', width: 80, align: 'left', sortable: false },
        { label: '捆包号', name: 'FBatchNo', width: 80, align: 'left', sortable: false },
        { label: '发交重量(kg)', name: 'FQuantity_KP', width: 90, align: 'right', sortable: false },
        { label: '实收重量(kg)', name: 'FQuantity', width: 90, align: 'right', sortable: false },
        { label: '计划重量(kg)', name: 'FQuantity_B', width: 90, align: 'right', sortable: false },
        { label: '入库张数', name: 'FZS_KP', width: 80, align: 'right', sortable: false },
        { label: '实收张数', name: 'FZS', width: 80, align: 'right', sortable: false },
        { label: '计划张数', name: 'FZS_B', width: 80, align: 'right', sortable: false },
        { label: '包装数量', name: 'FConQuatity', width: 80, align: 'right', sortable: false },
        { label: '采购单价(元/kg)', name: 'FPrice', width: 120, align: 'right', sortable: false },
        { label: '采购金额(元)', name: 'FMoney', width: 100, align: 'right', sortable: false },
        { label: '计划单价(元/kg)', name: 'PlanePrice', width: 120, align: 'right', sortable: false },
        { label: '计划金额(元)', name: 'PlaneMoney', width: 100, align: 'right', sortable: false },
        { label: '炉批号', name: 'FOvenNum', width: 80, align: 'left', sortable: false },
        { label: '出厂日期', name: 'WagonNumber', width: 80, align: 'center', sortable: false },
        { label: '标准编号', name: 'StandardNumber', width: 80, align: 'left', sortable: false },
        { label: '特殊要求', name: 'MaterialDemand', width: 80, align: 'left', sortable: false },
        { label: '凭证编号', name: 'FCredence', width: 80, align: 'left', sortable: false },
        { label: '备注', name: 'FDescription', width: 80, align: 'left', sortable: false },
        { label: '制造单位编码', name: 'FProCompanyNO', width: 80, align: 'left', sortable: false },
        { label: '制造单位名称', name: 'FProCompanyName', width: 80, align: 'left', sortable: false },
        { label: '仓库编号', name: 'FStoreNO', width: 80, align: 'left', sortable: false },
        { label: '仓库名称', name: 'FStoreName', width: 80, align: 'left', sortable: false },
        { label: '定置编号', name: 'FStoreSetNO', width: 80, align: 'left', sortable: false },
        { label: '输入人员', name: 'FCreateBy', width: 80, align: 'left', sortable: false },
        { label: '输入日期', name: 'FCreateDate', width: 70, align: 'center', sortable: false },
        { label: '输入时间', name: 'FCreateTime', width: 70, align: 'center', sortable: false },
        { label: '审核人员', name: 'FAuditingBy', width: 80, align: 'left', sortable: false },
        { label: '审核日期', name: 'FAuditingDate', width: 70, align: 'center', sortable: false },
        { label: '审核时间', name: 'FAuditingTime', width: 70, align: 'center', sortable: false },
        { label: '明细ID(隐藏)', name: 'FDocuListID', width: 20, align: 'center', sortable: false, hidden: true },
        { label: '发生方式编码(隐藏)', name: 'FDocuTypeNO', width: 20, align: 'center', sortable: false, hidden: true },
        { label: '材料分类编码(隐藏)', name: 'MaterialNO', width: 20, align: 'center', sortable: false, hidden: true },
        { label: '摘要说明(隐藏)', name: 'FDescription_DOC', width: 20, align: 'center', sortable: false, hidden: true },
    ];
    $(function () {
        initControl();
        gridList();
    });
    function initControl() {
        printItemTemplate = $("#print1 .page").html();
        $("input[type='radio'][value=" + currStatus + "].category").prop("checked", true);
        $("input[type='radio'].category").on("click", function () {
            var status = $("input[type='radio'].category:checked").val();
            if (currStatus != status) {
                window.location.href = '/WareHouse/MaterialStore/MaterialStoreEnter?status=' + status;
            }
        });
        initBindSelect("#form1");
    }
    function gridList() {
        var status = $("input[type='radio'].category:checked").val();
        if (status == 0) {
            showGridList1();
        } else {
            showGridList2();
        }
    }
    function showGridList1() {
        $("#grid1").show();
        $("#grid2").hide();
        $("#btn_group .grid1_btn").show();
        gridList1();
    }
    function showGridList2() {
        $("#grid1").hide();
        $("#grid2").show();
        $("#btn_group .grid2_btn").show();
        gridList2();
    }    
    function gridList1() {
        var $gridList1 = $("#gridList1");
        $gridList1.dataGrid({
            url: "/WareHouse/MaterialStore/GetMaterialStoreEnterListJson",
            postData: $("#form1").formSerialize(),
            height: $(window).height() - 118,
            colModel: columns,
            pager: "#gridPager1",
            sortname: 'FCreateDate DESC ,FCreateTime DESC',
            viewrecords: true,  //是否显示行数
            rownumWidth: 40,
            gridComplete: function () {

            },
            loadComplete: function () {
                var ids = $gridList1.jqGrid("getDataIDs");
                var length = ids.length;
                if (length > 0) {
                    if (currRowId == 0) {
                        currRowId = 1;
                    } else if (currRowId > length) {
                        currRowId = length;
                    }
                }
                if (currRowId > 0) {
                    $gridList1.jqGrid('setSelection', currRowId);
                    var $grid = $('#gview_gridList1 .ui-jqgrid-bdiv');
                    if (isJump) {
                        $grid.setScrollTop(length, currRowId);
                        isJump = false;
                    } else {
                        var top = $grid.scrollTop();
                        $grid.scrollTop(top + 1);
                    }
                }
            },
            onSelectRow: function (rowid) {
                currRowId = rowid;
                var rowData = $gridList1.jqGrid('getRowData', currRowId);
                setDataByJson("#eidt_div", rowData);
            },
            onPaging: function (page_btn) {
                currRowId = 0;
            }
        });
        $gridList1.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        $gridList1.jqGrid('setFrozenColumns');

        $("#btn_search").click(function () {
            reloadGrid1();
        });
    }
    function reloadGrid1() {
        $("#gridList1").jqGrid('setGridParam', {
            postData: $("#form1").formSerialize(),
        }).trigger('reloadGrid');
    }
    function gridList2() {
        var $gridList2 = $("#gridList2");
        $gridList2.dataGrid({
            url: "/WareHouse/MaterialStore/GetMaterialStoreEnterDocListJson",
            postData: $("#form1").formSerialize(),
            height: $(window).height() - 118,
            colModel: columns,
            pager: "#gridPager2",
            sortname: 'FCreateDate DESC ,FCreateTime DESC',
            viewrecords: true,  //是否显示行数
            rownumWidth: 40,
            gridComplete: function () {

            },
            loadComplete: function () {
                var rowDatas = $gridList2.jqGrid("getRowData");
                var length = rowDatas.length + 1;
                if (length > 0) {
                    if (currRowId == 0) {
                        currRowId = 1;
                    } else if (currRowId > length) {
                        currRowId = length;
                    }
                }
                if (currRowId > 0) {
                    $gridList2.jqGrid('setSelection', currRowId);
                    var $grid = $('#gview_gridList2 .ui-jqgrid-bdiv');
                    if (isJump) {
                        $grid.setScrollTop(length, currRowId);
                        isJump = false;
                    } else {
                        var top = $grid.scrollTop();
                        $grid.scrollTop(top + 1);
                    }
                }
            },
            onSelectRow: function (rowid) {
                currRowId = rowid;
            },
            onPaging: function (page_btn) {
                currRowId = 0;
            }
        });
        $gridList2.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        $gridList2.jqGrid('setFrozenColumns');

        $("#btn_search").click(function () {
            reloadGrid2();
        });
    }
    function reloadGrid2() {
        $("#gridList2").jqGrid('setGridParam', {
            postData: $("#form1").formSerialize(),
        }).trigger('reloadGrid');
    }
    function grid_chb_selectAll() {
        var txt = $('#grid_chb_selectAll').text();
        if (txt == "全选") {
            $('.grid_chb_select').prop("checked", true);
            $('#grid_chb_selectAll').text("反选");
        } else {
            $('.grid_chb_select').prop("checked", false);
            $('#grid_chb_selectAll').text("全选");
        }

    }
    function btn_add() {
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/WareHouse/MaterialStore/MaterialStoreEnterInput?status=I"
        });
    }
    function btn_add2() {
        var currFDocuNO = '';
        var rowData = $("#gridList1").jqGrid('getRowData', currRowId);
        currFDocuNO = rowData.FDocuNO;
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/WareHouse/MaterialStore/MaterialStoreEnterInput?status=I&currFDocuNO=" + currFDocuNO
        });
    }
    function btn_remove() {
        var rowData = $("#gridList1").jqGrid('getRowData', currRowId);
        if (rowData.FDocuListID != undefined) {
            $.modalConfirm("注：您确定要【删除】该条数据吗？", function (r) {
                if (r) {
                    $.submitForm({
                        url: "/WareHouse/MaterialStore/SubmitMaterialStoreEnterForm?status=D",
                        param: { keyValue: rowData.FDocuListID },
                        success: function () {
                            reloadGrid1();
                        }
                    })
                }
            });
        } else {
            $.modalAlert("注：您没有选中任何行。", "warning");
        }

    }
    function btn_edit() {
        var rowData = $("#gridList1").jqGrid('getRowData', currRowId);
        //$('#btn_group').hide();
        //$('#eidt_div').show();
        //$('#operate_btn_group').show();
        //setDataByJson("#eidt_div", rowData);
        $.detailOpenTop({
            id: "OrderForm",
            title: '请修改原材料入库单据信息:',
            url: "/WareHouse/MaterialStore/MaterialStoreEnterOrderEdit?FDocuListID=" + rowData.FDocuListID,
            width: 900,
            height: 400,
        });
    }
    function reloadPageData() {
        reloadGrid1();
    }
    function btn_check() {
        var chk_value = [];
        $('#gbox_gridList1 input[type="checkbox"].grid_chb_select:checked').each(function () {
            if ($(this).val() != '') {
                //alert($.inArray($(this).val(), chk_value));
                if ($.inArray($(this).val(), chk_value) < 0) {
                    chk_value.push($(this).val());
                }
            }
        });
        if (chk_value.length <= 0) {
            $.modalAlert("注：您没有勾选任何数据。", "warning");
        } else {
            $.modalConfirm("注：您确定要【审核】勾选的数据吗？", function (r) {
                if (r) {
                    $.submitForm({
                        url: "/WareHouse/MaterialStore/SubmitMaterialStoreEnterForm?status=P",
                        param: { keyValue: chk_value.join(',') },
                        success: function () {
                            reloadGrid1();
                        }
                    })
                }
            });
        }
    }
    function btn_back() {
        //$.modalAlert("功能正在建设中......", "warning");
        var rowData = $("#gridList2").jqGrid('getRowData', currRowId);
        if (rowData.FDocuListID != undefined) {
            $.modalConfirm("注：您确定要【冲红】该条数据吗？", function (r) {
                if (r) {
                    $.submitForm({
                        url: "/WareHouse/MaterialStore/SubmitMaterialStoreEnterForm?status=C",
                        param: { keyValue: rowData.FDocuListID, FDocuTypeNO: rowData.FDocuTypeNO },
                        success: function () {
                            reloadGrid2();
                        }
                    })
                }
            });
        } else {
            $.modalAlert("注：您没有选中任何行。", "warning");
        }
    }
    function btn_list() {
        var currFDocuNO;
        var status = $("input[type='radio'].category:checked").val();
        if (status == 0) {
            var rowData = $("#gridList1").jqGrid('getRowData', currRowId);
            currFDocuNO = rowData.FDocuNO;
            if (currFDocuNO != undefined) {
                $.detailOpen({
                    id: "Detail",
                    title: "",
                    url: "/WareHouse/MaterialStore/MaterialStoreEnterInput?status=B&FAccountDate=&currFDocuNO=" + currFDocuNO
                });
            } else {
                $.modalAlert("注：您没有选中任何行。", "warning");
            }
        } else {
            var rowData = $("#gridList2").jqGrid('getRowData', currRowId);
            currFDocuNO = rowData.FDocuNO;
            if (currFDocuNO != undefined) {
                $.detailOpen({
                    id: "Detail",
                    title: "",
                    url: "/WareHouse/MaterialStore/MaterialStoreEnterInput?status=B&FAccountDate=" + $('#FAccountDate').val() + "&currFDocuNO=" + currFDocuNO
                });
            } else {
                $.modalAlert("注：您没有选中任何行。", "warning");
            }
        }
    }
    function btn_edit_ok() {
        if (!$('#form2').formValid()) {

        } else {
            $.modalConfirm("注：您确定要【修改】该条数据吗？", function (r) {
                if (r) {
                    var param = { FDocuNO: $('#FDocuNO').val() };
                    param["detail"] = JSON.stringify($("#eidt_div").formSerialize());
                    $.submitForm({
                        url: "/WareHouse/MaterialStore/SubmitMaterialStoreEnterForm?status=U",
                        param: param,
                        success: function () {
                            reloadGrid1();
                        }
                    })
                }
            });
        }
    }
    function btn_cancel() {
        $('#btn_group').show();
        $('#eidt_div').hide();
        $('#operate_btn_group').hide();
    }
    function btn_excel() {
        //$.modalAlert("功能正在建设中......", "warning");
        var url = "/Common/ExcelExport?" + init_sql();
        location.href = url;
    }
    function init_sql() {
        var status = $("input[type='radio'].category:checked").val();
        if (status == 0) {
            return init_sql1();
        } else {
            return init_sql2();
        }
    }
    function init_sql1() {
        var tablename = "V_CLK_42_MX_MaterialProListAcco";
        var condition = "(FDocuTypeNO ='LR' OR FDocuTypeNO ='LZ' OR FDocuTypeNO ='LY'  OR FDocuTypeNO ='LF'  OR  FDocuTypeNO='LI')";
        var cols = [];
        //获取列字段
        var sortname = $("#gridList1").jqGrid('getGridParam', 'sortname');
        var colModel = $("#gridList1").jqGrid('getGridParam', 'colModel');
        for (var i = 0; i < colModel.length; i++) {
            var columnHidden = colModel[i].hidden;
            var columnName = colModel[i].name;
            var columnLabel = colModel[i].label;
            if (columnHidden == false && columnName != "rn" && columnName != "") {
                if (columnLabel != '') {
                    cols.push(columnName + ' [' + columnLabel.replace(/<[^>]+>/g, "") + ']');
                } else {
                    cols.push(columnName);
                }
            }
        }
        if ($('#FDocuNO2').val() != '') {
            condition += " AND (FDocuNO LIKE '%" + $('#FDocuNO2').val() + "%')";
        }
        if ($('#FHappenComNO').val() != '') {
            condition += " AND (FHappenComNO = '" + $('#FHappenComNO').val() + "')";
        }
        if ($('#MaterialCode2').val() != '') {
            condition += " AND (MaterialCode LIKE '%" + $('#MaterialCode2').val() + "%')";
        }
        if ($('#MaterialSizes2').val() != '') {
            condition += " AND (MaterialSizes LIKE '%" + $('#MaterialSizes2').val() + "%')";
        }
        if ($('#FStoreNO').val() != '') {
            condition += " AND (FStoreNO = '" + $('#FStoreNO').val() + "')";
        }
        if ($('#FCurDate').val() != '') {
            condition += " AND (FCurDate = '" + $('#FCurDate').val() + "')";
        }
        if ($('#FCredence').val() != '') {
            condition += " AND (FCredence LIKE '%" + $('#FCredence').val() + "%')";
        }
        if ($('#FCertificateListID').val() != '') {
            condition += " AND (FCertificateListID LIKE '%" + $('#FCertificateListID').val() + "%')";
        }
        condition += " AND (FAccountDate = '" + $('#FAccountDate').val() + "')";
        var sql = "SELECT " + cols.join(',') + " FROM " + tablename + " WHERE " + condition + " ORDER BY " + sortname;
        return "sql=" + sql;
    }
    function init_sql2() {
        var tablename = "V_CLK_44_MX_MaterialProListAcco_Mid";
        if (AccountDate != $('#FAccountDate').val()) {
            tablename = "V_CLK_46_MX_MaterialProListAcco_Arc";
        }
        var condition = "(FDocuTypeNO ='LR' OR FDocuTypeNO ='LZ' OR FDocuTypeNO ='LY'  OR FDocuTypeNO ='LF'  OR  FDocuTypeNO='LI')";
        var cols = [];
        //获取列字段
        var sortname = $("#gridList2").jqGrid('getGridParam', 'sortname');
        var colModel = $("#gridList2").jqGrid('getGridParam', 'colModel');
        for (var i = 0; i < colModel.length; i++) {
            var columnHidden = colModel[i].hidden;
            var columnName = colModel[i].name;
            var columnLabel = colModel[i].label;
            if (columnHidden == false && columnName != "rn" && columnName != "") {
                if (columnLabel != '') {
                    cols.push(columnName + ' [' + columnLabel.replace(/<[^>]+>/g, "") + ']');
                } else {
                    cols.push(columnName);
                }
            }
        }
        if ($('#FDocuNO2').val() != '') {
            condition += " AND (FDocuNO LIKE '%" + $('#FDocuNO2').val() + "%')";
        }
        if ($('#FHappenComNO').val() != '') {
            condition += " AND (FHappenComNO = '" + $('#FHappenComNO').val() + "')";
        }
        if ($('#MaterialCode2').val() != '') {
            condition += " AND (MaterialCode LIKE '%" + $('#MaterialCode2').val() + "%')";
        }
        if ($('#MaterialSizes2').val() != '') {
            condition += " AND (MaterialSizes LIKE '%" + $('#MaterialSizes2').val() + "%')";
        }
        if ($('#FStoreNO').val() != '') {
            condition += " AND (FStoreNO = '" + $('#FStoreNO').val() + "')";
        }
        if ($('#FCurDate').val() != '') {
            condition += " AND (FCurDate = '" + $('#FCurDate').val() + "')";
        }
        if ($('#FCredence').val() != '') {
            condition += " AND (FCredence LIKE '%" + $('#FCredence').val() + "%')";
        }
        if ($('#FCertificateListID').val() != '') {
            condition += " AND (FCertificateListID LIKE '%" + $('#FCertificateListID').val() + "%')";
        }
        condition += " AND (FAccountDate = '" + $('#FAccountDate').val() + "')";
        var sql = "SELECT " + cols.join(',') + " FROM " + tablename + " WHERE " + condition + " ORDER BY " + sortname;
        return "sql=" + sql;
    }
    function btn_print() {
        //$.modalAlert("功能正在建设中......", "warning");
        var status = $("input[type='radio'].category:checked").val();
        if (status == 0) {
            print_data_1();
        } else {
            print_data_2();
        }
    }
    function print_data_1() {
        var chk_value = [];
        $('#gbox_gridList1 input[type="checkbox"].grid_chb_select:checked').each(function () {
            if ($(this).val() != '') {
                var item = "'" + $(this).val() + "'";
                if ($.inArray(item, chk_value) < 0) {
                    chk_value.push(item);
                }
            }
        });
        if (chk_value.length <= 0) {
            $.modalAlert("注：请勾选需要打印的单据。", "warning");
        } else {
            var columnInfos = {
                "FHappenComName": "来料单位名称",
                "FCredence": "凭证编号",
                "FCurDate": "单据日期",
                "FDescription_DOC": "摘要说明",
                "FDocuNO": "单据编号",
                "MaterialName": "材料分类",
                "MaterialCode": "材料牌号",
                "MaterialSizes": "材料规格",
                "FQuantity_KP": "开票重量",
                "FQuantity": "实际重量",
                "FPrice": "单价(元)",
                "FMoney": "金额(元)",
                "FStoreName": "仓库名称",
                "FStoreSetNO": "仓库定置定位",
                "FDescription": "备注说明"
            };
            $.submitForm({
                url: "/WareHouse/MaterialStore/GetPrintDetailsData",
                param: { isDefaultDate: AccountDate == $("#FAccountDate").val(), isArchive: false, ids: chk_value.join(",") },
                success: function (result) {
                    //alert(result.data.length);
                    var container = $("#print1").empty();
                    var indexCols = "unitName,title".split(",");
                    result.data.forEach(function (item) {
                        item["unitName"]="北汽福田汽车股份有限公司冲压工厂",
                        item["title"]="原材料库入库单",
                        //alert(item["FDocuNO"]);
                        item["bar_code"] = "/Common/GetBarCode?text={0}&width=300&height=90".format(item["FDocuNO"]);
                        item["qr_code"] = "/Common/GetQrcode?text={0}".format(item["FDocuNO"]);
                        var total_page = 0, rows = 16, maxRows = item.dataList.length, idx = 0;
                        total_page = Math.ceil(maxRows / (rows * 1.0));
                        item["total"] = maxRows;
                        //alert(total_page);
                        for (var i = 0; i < total_page; i++) {
                            var start = i * rows, end = (i + 1) * rows;
                            (maxRows < end) && (end = Math.ceil(maxRows % rows));
                            var pageCols = "total,curUser,curDate,curTime,unitName,title,bar_code,qr_code,FDocuNO,FCredence,FHappenComName,FCurDate,FDescription_DOC".split(',');
                            var pageData = { total_page: total_page, page: (i + 1), dataList: [], bill_total: 0, real_total: 0, amount_total: 0 };
                            pageCols.forEach(function (pageCol) {
                                pageData[pageCol] = item[pageCol];
                            });
                            var deleteCols = "FHappenComName,FCredence,FCurDate,FDescription_DOC,FDocuNO".split(',');
                            for (var j = start; j < end; j++) {
                                deleteCols.forEach(function (deleteCol) {
                                    delete item.dataList[j][deleteCol];
                                });
                                pageData.dataList.push(item.dataList[j]);
                                pageData.bill_total += parseInt(item.dataList[j]["FQuantity_KP"], 10);
                                pageData.real_total += parseInt(item.dataList[j]["FQuantity"], 10);
                                pageData.amount_total += parseFloat(item.dataList[j]["FMoney"]);
                            }
                            buildPrintData(pageData, columnInfos).appendTo(container);
                        }
                    });
                    $("#print1").jqprint();
                }
            })
        }
    }
    function print_data_2() {
        var chk_value = [];
        $('#gbox_gridList2 input[type="checkbox"].grid_chb_select:checked').each(function () {
            if ($(this).val() != '') {
                var item = "'" + $(this).val() + "'";
                if ($.inArray(item, chk_value) < 0) {
                    chk_value.push(item);
                }
            }
        });
        if (chk_value.length <= 0) {
            $.modalAlert("注：请勾选需要打印的单据。", "warning");
        } else {
            var columnInfos = {
                "FHappenComName": "来料单位名称",
                "FCredence": "凭证编号",
                "FCurDate": "单据日期",
                "FDescription_DOC": "摘要说明",
                "FDocuNO": "单据编号",
                "MaterialName": "材料分类",
                "MaterialCode": "材料牌号",
                "MaterialSizes": "材料规格",
                "FQuantity_KP": "开票重量",
                "FQuantity": "实际重量",
                "FPrice": "单价(元)",
                "FMoney": "金额(元)",
                "FStoreName": "仓库名称",
                "FStoreSetNO": "仓库定置定位",
                "FDescription": "备注说明"
            };
            $.submitForm({
                url: "/WareHouse/MaterialStore/GetPrintDetailsData",
                param: { isDefaultDate: AccountDate == $("#FAccountDate").val(), isArchive: true, ids: chk_value.join(",") },
                success: function (result) {
                    //alert(result.data.length);
                    var container = $("#print1").empty();
                    var indexCols = "unitName,title".split(",");
                    result.data.forEach(function (item) {
                        item["unitName"] = "北汽福田汽车股份有限公司冲压工厂",
                        item["title"] = "原材料库入库单",
                        item["bar_code"] = "/Common/GetBarCode?text={0}&width=300&height=90".format(item["FDocuNO"]);
                        item["qr_code"] = "/Common/GetQrcode?text={0}".format(item["FDocuNO"]);
                        var total_page = 0, rows = 16, maxRows = item.dataList.length, idx = 0;
                        total_page = Math.ceil(maxRows / (rows * 1.0));
                        item["total"] = maxRows;
                        for (var i = 0; i < total_page; i++) {
                            var start = i * rows, end = (i + 1) * rows;
                            (maxRows < end) && (end = Math.ceil(maxRows % rows));
                            var pageCols = "total,curUser,curDate,curTime,unitName,title,bar_code,qr_code,FDocuNO,FCredence,FHappenComName,FCurDate,FDescription_DOC".split(',');
                            var pageData = { total_page: total_page, page: (i + 1), dataList: [], bill_total: 0, real_total: 0, amount_total: 0 };
                            pageCols.forEach(function (pageCol) {
                                pageData[pageCol] = item[pageCol];
                            });
                            //alert(pageData.bar_code);
                            var deleteCols = "FHappenComName,FCredence,FCurDate,FDescription_DOC,FDocuNO".split(',');
                            for (var j = start; j < end; j++) {
                                deleteCols.forEach(function (deleteCol) {
                                    delete item.dataList[j][deleteCol];
                                });
                                pageData.dataList.push(item.dataList[j]);
                                pageData.bill_total += parseInt(item.dataList[j]["FQuantity_KP"], 10);
                                pageData.real_total += parseInt(item.dataList[j]["FQuantity"], 10);
                                pageData.amount_total += parseFloat(item.dataList[j]["FMoney"]);
                            }
                            buildPrintData(pageData, columnInfos).appendTo(container);
                        }
                    });
                    $("#print1").jqprint();
                }
            })
        }
    }
    function buildPrintData(data, columnInfos) {
        var pageItem = $("<div>").addClass("page"), table = $("<table>"), cols = [];
        data.dataList.forEach(function (item) {
            !!cols.length || (function () {
                var header = $("<tr>");
                for (var idx in item) {
                    cols.push(idx);

                    $("<th>").html(columnInfos[idx]).appendTo(header);
                }
                header.appendTo(table);
            })();
            !!cols.length && (function () {
                var tr = $("<tr>");
                for (var idx in cols) {
                    $("<td>").html(item[cols[idx]]).appendTo(tr);
                }
                tr.appendTo(table);
            })();
        });
        data["table"] = "<table>{0}</table>".format(table.html());
        pageItem.html(printItemTemplate.format(data));
        return pageItem;
    }
</script>
<div id="layout" style="height: 100%; width: 100%;">
    <form id="form1">
        <div id="condition_group" style="padding: 12px 0 5px 0; padding-left:0px; border-bottom:1px solid #ccc;position:relative;" class="line-table input-width-70">
            <div class="btn-group" style="margin-top:-5px;">
                <input id="radio11" class="category" name="category" type="radio" value="0" /><label for="radio11" class="suffix">登记</label><br />
                <input id="radio12" class="category" name="category" type="radio" value="1" /><label for="radio12" class="suffix">档案</label> &nbsp;
            </div>
            <div class="btn-group" style="margin-top:-9px;">
                单据编号<br /><input id="FDocuNO2" name="FDocuNO" type="text" class="form-control" />
            </div>
            <div class="btn-group  input-width-140" style="margin-top:-9px;">
                来料单位<br />
                <select id="FHappenComNO" name="FHappenComNO" class="form-control">
                    <option value="">&nbsp;</option>
                    @foreach (var item in ViewBag.fhappencomList)
                    {
                        <option value="@item.UnitNO">@item.UnitNO @item.UnitShortName</option>
                    }
                </select>
            </div>
            <div class="btn-group" style="margin-top:-9px;">
                材料牌号<br /><input id="MaterialCode2" name="MaterialCode" type="text" class="form-control" />
            </div>
            <div class="btn-group" style="margin-top:-9px;">
                材料规格<br /><input id="MaterialSizes2" name="MaterialSizes" type="text" class="form-control" />
            </div>
            <div class="btn-group input-width-105" style="margin-top:-9px;">
                仓库<br />
                <select id="FStoreNO" name="FStoreNO" class="form-control">
                    <option value="">&nbsp;</option>
                    @foreach (var item in ViewBag.fstoreList)
                    {
                        <option value="@item.FStoreNO">@item.FStoreNO @item.FStoreName</option>
                    }
                </select>
            </div>
            <div class="btn-group" style="margin-top:-9px;">
                来料日期<br /><input id="FCurDate" name="FCurDate" type="text" class="form-control input-wdatepicker" style="width:90px !important;" onclick="WdatePicker()" />
            </div>
            <div class="btn-group" style="margin-top:-9px;">
                凭证编号<br /><input id="FCredence" name="FCredence" type="text" class="form-control" />
            </div>
            <div class="btn-group" style="margin-top:-9px;">
                合同编号<br /><input id="FCertificateListID" name="FCertificateListID" type="text" class="form-control" />
            </div>
            <div class="btn-group" style="margin-top:-9px;">
                台账日期<br /><input id="FAccountDate" name="FAccountDate" type="text" class="form-control input-wdatepicker" onclick="WdatePicker({ dateFmt: 'yyyyMM', isShowToday: false, isShowClear: false });" value="@ViewBag.accountDate" />
            </div>
            <div class="btn-group">
                <a id="btn_search" class="btn btn-primary center-block btn-small" onclick=""><span class="glyphicon glyphicon-search"></span> 查询</a>
            </div>
            <div id="operate_btn_group" class="btn-group" style="display: none;">
                <a class="btn btn-primary center-block" onclick="btn_edit_ok();">   <span class="glyphicon "></span>修改</a>
                <a class="btn btn-primary center-block" onclick="btn_cancel();"><span class="glyphicon "></span>关闭</a>
            </div>

            <div id="btn_group" class="btn-group" style="position: absolute; right: 5px; top:13px">
                <a id="btn_reload" class="btn btn-primary center-block btn-small grid1_btn grid2_btn" style="display:none;" onclick="$.reload()">  <span class="glyphicon glyphicon-refresh"> </span> 刷新</a>
                <a id="btn_add" class="btn btn-primary center-block btn-small grid1_btn" style="display:none;" onclick="btn_add()">   <span class="glyphicon glyphicon-plus">    </span> 输入</a>
                <a id="btn_remove" class="btn btn-primary center-block btn-small grid1_btn" style="display:none;" onclick="btn_remove()"><span class="glyphicon glyphicon-trash">   </span> 删除</a>
                <a id="btn_edit" class="btn btn-primary center-block btn-small grid1_btn" style="display:none;" onclick="btn_edit()">  <span class="glyphicon glyphicon-edit">    </span> 修改</a>
                <a id="btn_check" class="btn btn-primary center-block btn-small grid1_btn" style="display:none;" onclick="btn_check()"><span class="glyphicon glyphicon-pencil">    </span> 审核</a>
                <a id="btn_back" class="btn btn-primary center-block btn-small grid2_btn" style="display:none;" onclick="btn_back()"><span class="glyphicon glyphicon-share-alt">    </span> 冲红</a>
                <a id="btn_list" class="btn btn-primary center-block btn-small grid1_btn grid2_btn" style="display:none;" onclick="btn_list()"><span class="glyphicon glyphicon-th-list">    </span> 单据</a>
                <a id="btn_excel" class="btn btn-primary center-block btn-small grid1_btn grid2_btn" style="display:none;" onclick="btn_excel()"> <span class="glyphicon glyphicon-download"></span> 导出</a>
                <a id="btn_print" class="btn btn-primary center-block btn-small grid1_btn grid2_btn" style="display:none;" onclick="btn_print()"> <span class="glyphicon glyphicon-print">   </span> 打印</a>
            </div>
        </div>
    </form>
    <form id="form2">
        <table id="eidt_div" class="form" style="margin: 3px 30px 3px 0; display: none;">
            <tr>
                <th class="formTitle" style="width:70px;">单据编号</th>
                <td class="formValue" style="width:180px;">
                    <input id="FDocuNO" name="FDocuNO" type="text" class="form-control required" readonly="readonly" value="" />
                    <input id="FDocuListID" name="FDocuListID" type="text" value="" style="display:none;" />
                </td>
                <th class="formTitle" style="width:80px">零件单价</th>
                <td class="formValue input-width-105" style="">
                    <input id="FPrice_KP" name="FPrice_KP" type="text" class="form-control text-right required decimal" style="width:80px;margin-left:0px;" /><label style="margin-left:12px">元</label>
                </td>
            </tr>
            <tr>
                <th class="formTitle" style="width:100px">零件编号</th>
                <td class="formValue" style="width:180px;">
                    <input id="FProductionNO" name="FProductionNO" type="text" class="form-control" readonly="readonly" maxlength="50" value="" />
                </td>
                <th class="formTitle" style="width:80px">实际数量</th>
                <td class="formValue input-width-105" style="">
                    <input id="FQuantity" name="FQuantity" type="text" class="form-control text-right required digits" style="width:80px;margin-left:0px;" /><label style="margin-left:12px">件</label>
                </td>
            </tr>
        </table>
    </form>
    <div id="grid1">
        <table id="gridList1"></table>
        <div id="gridPager1"></div>
    </div>
    <div id="grid2" style="">
        <table id="gridList2"></table>
        <div id="gridPager2"></div>
    </div>
    <div id="print1" class="print">
        <div class="page">
            <header>
                <h2>{unitName}</h2>
                <h1>{title}</h1>
                <aside>
                    <img src="{bar_code}" alt="bar_code" title="bar_code" />
                    <img src="{qr_code}" alt="qr_code2" title="qr_code2" />
                </aside>
            </header>
            <section>
                <div class="item item_r">
                    <label>单据编号:</label>{FDocuNO}
                </div>
                <div class="item">
                    <label>来料单位:</label>{FHappenComName}
                </div>
                <div class="item">
                    <label>入库日期:</label>{FCurDate}
                </div>
                <div class="item">
                    <label>摘要说明:</label>{FDescription_DOC}
                </div>
            </section>
            <div class="table_c">
                {table}
            </div>
            <footer>
                <div class="line">
                    <aside>
                        <div class="item">
                            <label>合计：{total}</label>
                        </div>
                        <div class="item">
                            <label>开票数量合计：{bill_total}</label>
                        </div>
                        <div class="item">
                            <label>实际数量合计：{real_total}</label>
                        </div>
                        <div class="item">
                            <label>金额合计：{amount_total}</label>
                        </div>
                    </aside>
                </div>
                <div class="line">
                    <div class="item item_r">
                        <span>第{page}页 </span><span>共{total_page}页</span>
                    </div>
                    <div class="item">
                        <label>打印人员：</label>{curUser}
                    </div>
                    <div class="item">
                        <label>打印日期：</label>{curDate}
                    </div>
                    <div class="item">
                        <label>打印时间：</label>{curTime}
                    </div>
                </div>
            </footer>
        </div>
    </div>
</div>